;(function($){
    $.fn.banner=function(imgs,ops){
        ops = ops?ops:{};
        let {btns=true,list=true,autoPlay=true,delayTime=3000,index=1,moveTime=1000} = ops;
        const that = this;
        let prev=0;
        let str = "";
        imgs.forEach(val => {
            str+=`<img src="${val.src}" alt="${val.alt}" title="${val.title}">`
        });
        const pice=$("<div class='imgs'>"+str+"</div>").appendTo(this).children("img");
        pice.css("left",0);

        function move(prev,index){
            pice.eq(prev-1).css({"opacity":0.3,display:"none"}).animate({opacity:0.3,display:"none"},moveTime).end().eq(index-1).css({"opacity":1,display:"block"}).animate({opacity:1,display:"block"},moveTime).eq(index);
            $(that).children(".list").children("span").css({background:"rgba(200, 200, 200, 0.5)"}).eq(index-1).css({background:"red"})
        }
        if(list){
            let str = "";
            imgs.forEach((val,idx)=>{
                str+=`<span>${idx+1}</span>`;
            })
            $("<div class='list'>"+str+"</div>").appendTo(this).children("span").eq(index-1).css({background:"red"}).end().click(function(){
                if($(this).index()+1>index){
                    move(index,$(this).index()+1)
                }
                if($(this).index()+1<index){
                    move(index,$(this).index()+1)
                }
                index = $(this).index()+1;

                return false;
            })         
        }
        function rightClick(){
            if(index === imgs.length){
                index = 1;
                prev = imgs.length;
            }else{
                index++;
                prev = index-1
            }
            move(prev,index);
        }
        if(autoPlay){
            let t = setInterval(()=>{
                rightClick()
            },delayTime)
            that.hover(function(){
                clearInterval(t)
            },function(){
                t = setInterval(()=>{
                    rightClick()
                },delayTime)
            })
        }
    }
})(jQuery);